#!/bin/sh

#
# This script is used to provide an automation for the SimpleChat test class.
#
# It simply read an input file and write each line after a given delay to
# stdin of a Chat test class.
#
# This script can be used with argument : a file which
# contains lines like "5:hello" (to print "hello" 5sec
# after the previous line).
# If no argument is given, stdin is used.
#

#
# This script depends on run_debug_chat.sh.
#
# A way to use this script is shown below :
#    ./chat_automation.sh
#    5: dest pat
#    1:hello, how are you ?
#    5:I'me fine thank U
#    9:Bye!
#    1: exit
#[CTRL+D]
#(lines from "5:" to "exit" can be given througt a file)

#
# created by $Author: 85guigui $
# version $Id: chat_automation.sh 282 2007-06-05 12:50:06Z 85guigui $
#

#--


genere() {

# If no argument, getting from stdin
IFS=$'\n'
for i in $(cat $1)
do

  sleep "$(echo "$i" | cut -d ':' -f 1)"
  echo "$i" | cut -d ':' -f 2-

done
}

cd $(dirname "$0")
genere $* | ./run_debug_chat.sh | tee  /tmp/chat_stdout__$$.log

